
//新闻纵向滚动条
'use strict';
var React = require('react');
class ReNoticeBar extends React.Component {
    constructor(props) {
        super(props);
        this.state={
            top:0
        };
        this.getMainClass=this.getMainClass.bind(this);
    }

    //渲染主体内容
    renderContent(){
        if(this.props.data) {
            return this.props.data.map((item, i)=> {
                return <li key={"ReNoticeBarItem"+i}><a href={item.reHref}
                                                        className="ReNoticeBarItemText">{item.leftTitle}</a><a
                    className="ReNoticeBarItemTime">{item.rightTitle}</a></li>
            });
        }
    }

    componentDidMount(){
        setInterval(()=>{
            if(this.state.top==this.props.data.length-1){
                this.setState({
                    top:0
                });
            }
            else{
                this.setState({
                    top:this.state.top+1
                });
            }
        },3000)
    }

    getMainClass(){
        if(this.props.reClass){
            return "ReNoticeBarContainer "+this.props.reClass;
        }
        else{
            return "ReNoticeBarContainer";
        }
    }

    render(){
        var style={
            top:this.state.top*-28+'px'
        };
        return <div className={this.getMainClass()}>
            <ul style={style}>
                {this.renderContent()}
            </ul>
        </div>
    }
}

module.exports=ReNoticeBar;